home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / DistUpgrade / DistUpgradeGettext.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  1.7 KB  |  44 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import logging
  5. import gettext as mygettext
  6.  
  7. def _verify(message, translated):
  8.     ''' 
  9.     helper that verifies that the message and the translated 
  10.     message have the same number (and type) of % args
  11.     '''
  12.     arguments_in_message = message.count('%') - message.count('\\%')
  13.     arguments_in_translation = translated.count('%') - translated.count('\\%')
  14.     return arguments_in_message == arguments_in_translation
  15.  
  16.  
  17. def gettext(message):
  18.     '''
  19.     version of gettext that logs errors but does not crash on incorrect
  20.     number of arguments
  21.     '''
  22.     if message == '':
  23.         return ''
  24.     translated_msg = mygettext.gettext(message)
  25.     if not _verify(message, translated_msg):
  26.         logging.error("incorrect translation for message '%s' to '%s' (wrong number of arguments)" % (message, translated_msg))
  27.         return message
  28.     return translated_msg
  29.  
  30.  
  31. def ngettext(msgid1, msgid2, n):
  32.     '''
  33.     version of ngettext that logs errors but does not crash on incorrect
  34.     number of arguments
  35.     '''
  36.     translated_msg = mygettext.ngettext(msgid1, msgid2, n)
  37.     if not _verify(msgid1, translated_msg):
  38.         logging.error("incorrect translation for ngettext message '%s' plural: '%s' to '%s' (wrong number of arguments)" % (msgid1, msgid2, translated_msg))
  39.         if n == 1:
  40.             return msgid1
  41.         return msgid2
  42.     return translated_msg
  43.  
  44.